<?php

namespace App\Http\Controllers\Admin\PayAndConsume;

use App\Http\Requests\Admin\PayAndConsume\StatDataRequest;
use App\Http\Requests\Admin\PayAndConsume\PayTradeRequest;
use App\Http\Requests\Admin\PayAndConsume\PayGradeRequest;
use Illuminate\Http\Request;
use App\Services\PayAndConsume\PayService;
use App\Services\PayAndConsume\StatService;
use App\Http\Controllers\Admin\BaseController;

class PayController extends BaseController
{
    /**
     * ActionLogsController constructor.
     * @param $actionLogsService
     */
    public function __construct(PayService $payService, StatService $statService)
    {
        $this->payService = $payService;
        $this->statService = $statService;
    }

    //充值排行
    public function rank(StatDataRequest $request)
    {
        $reqUniqueId = $request->unique_id;
        $reqChannelId = $request->channel_id;
        $reqStartTime = $request->start_time;
        $reqEndTime = $request->end_time;
        $reqPageSize = $request->page_size;
        $reqDataType = $request->data_type;

        $payRank = $this->payService->getPayRankByUniqueID($request);

        return $this->view(null, compact(['payRank', 'reqUniqueId', 'reqChannelId', 'reqStartTime', 'reqEndTime', 'reqPageSize', 'reqDataType']));
    }

    //充值详情
    public function detail(Request $request)
    {
        $detail = $this->payService->getDetailByAccount($request);

        return $this->view(null, compact(['detail']));
    }

    //每日充值统计
    public function stat(StatDataRequest $request)
    {
        $reqUniqueId = $request->unique_id;
        $reqChannelId = $request->channel_id;
        $reqStartTime = $request->start_time;
        $reqEndTime = $request->end_time;
        $reqDataType = $request->data_type;

        //获取渠道信息
        $stat = $this->statService->getStatByUniqueID($reqUniqueId, $reqStartTime, $reqEndTime);

        return $this->view(null, compact(['stat', 'reqUniqueId', 'reqChannelId', 'reqStartTime', 'reqEndTime', 'reqDataType']));
    }

    //玩家收支统计
    public function trade(PayTradeRequest $request)
    {
        $reqStartTime = $request->start_time;
        $reqEndTime = $request->end_time;
        $reqChannelId = $request->channel_id;
        $reqUniqueId = $request->unique_id;
        $reqPageSize = $request->page_size;

        $request['unique_id'] = $reqUniqueId;
        $trade = $this->payService->getTradeLogByUniqueID($request);

        return $this->view(null, compact(['trade', 'reqStartTime', 'reqEndTime', 'reqChannelId', 'reqUniqueId', 'reqPageSize']));
    }

    //充值档位统计
    public function grade(PayGradeRequest $request)
    {
        $reqStartTime = $request->start_time;
        $reqEndTime = $request->end_time;
        $reqChannelId = $request->channel_id;
        $reqUniqueId = $request->unique_id;
        $reqType = $request->type;
        $reqPageSize = $request->page_size;
        $reqDataType = $request->data_type;

        $types = $request->types;

        //饼图数据
        $piePayTimes = [];
        $piePayUsersX = [];
        $piePayUsersData = [];
        $data = $this->payService->getGradeByUniqueID($request, $piePayTimes, $piePayUsersX, $piePayUsersData);


        return $this->view(null,
            compact([
                'data', 'reqStartTime', 'reqEndTime', 'types',
                'reqChannelId', 'reqUniqueId', 'reqPageSize', 'piePayTimes', 'piePayUsersX',
                'piePayUsersData', 'reqType', 'reqDataType'
            ])
        );
    }
}
